package com.feedback.c;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.feedback.a.a;
import com.feedback.a.d;
import com.feedback.b.c;
import com.feedback.b.d;
import com.mobclick.android.t;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;

public class b extends Thread
{
  static final String a = b.class.getSimpleName();
  Context b;
  String c;
  String d;
  String e;
  int f;
  Handler g;

  public b(Context paramContext)
  {
    this.c = "http://feedback.whalecloud.com/feedback/reply";
    this.f = 0;
    this.b = paramContext;
    this.d = t.b(paramContext);
    this.e = t.d(paramContext);
  }

  public b(Context paramContext, Handler paramHandler)
  {
    this(paramContext);
    this.g = paramHandler;
  }

  public void run()
  {
    String str2;
    JSONArray localJSONArray2;
    String str4;
    Iterator localIterator = this.b.getSharedPreferences("feedback", 0).getAll().keySet().iterator();
    Object localObject = "";
    while (true)
    {
      String str1;
      while (true)
      {
        if (!(localIterator.hasNext()))
        {
          str2 = this.b.getSharedPreferences("UmengFb_Nums", 0).getString("maxReplyID", "RP0");
          if (!(d.a((String)localObject)))
            break label116;
          return;
        }
        str1 = (String)localIterator.next();
        if (((String)localObject).length() != 0)
          break;
        localObject = str1;
      }
      localObject = localObject + "," + str1;
    }
    label116: this.c = this.c + "?appkey=" + this.d + "&feedback_id=" + ((String)localObject);
    if (!(str2.equals("RP0")))
      this.c = this.c + "&startkey=" + str2;
    Log.d(a, this.c);
    String str3 = d.b(this.c);
    Intent localIntent = new Intent();
    localIntent.setAction("RetrieveReplyBroadcast");
    if (str3 != null);
    try
    {
      JSONArray localJSONArray1 = new JSONArray(str3);
      localJSONArray2 = localJSONArray1;
      str4 = c.a(this.b, localJSONArray2);
      Log.d(a, "newReplyIds :" + str4);
      if ((str4.length() == 0) || (str4.split(",").length == 0))
      {
        localIntent.putExtra("RetrieveReplyBroadcast", 0);
        this.b.sendBroadcast(localIntent);
      }
    }
    catch (JSONException localJSONException)
    {
      while (true)
      {
        while (true)
        {
          do
          {
            while (true)
            {
              localJSONException.printStackTrace();
              localJSONArray2 = null;
            }
            localIntent.putExtra("RetrieveReplyBroadcast", 1);
          }
          while (this.g == null);
          String[] arrayOfString = str4.split(",");
          int i = arrayOfString.length;
          a locala = c.b(this.b, arrayOfString[(i - 1)]).e;
          Message localMessage = new Message();
          Bundle localBundle = new Bundle();
          localBundle.putString("newReplyContent", locala.a());
          localMessage.setData(localBundle);
          this.g.sendMessage(localMessage);
        }
        localIntent.putExtra("RetrieveReplyBroadcast", -1);
      }
    }
  }
}